# -*- coding: utf-8 -*-
'''
    :file: error.py
    :author: -Farmer
    :url: https://blog.farmer233.top
    :date: 2021/04/27 20:26:04
'''
import os
from core.config import BASE_DIR
from core.controller.static import static
from core.utils.http import HttpResponse

def get_error_page(path):
    file_path = os.path.join(BASE_DIR, path)
    with open(file_path, 'r', encoding='utf-8') as f:
        data = f.read()
    return data

def page_not_found():
    """处理 400 异常"""
    # 获取404.html
    body = get_error_page('static/404.html')
    # body = '404'
    return HttpResponse(body, status=404)


def internal_server_error():
    """处理 500 异常"""
    # body = render_template('error/500.html')
    body = 500
    return HttpResponse(body, status=500)
